<?php

/**
 * home actions.
 *
 * @package    retailbrain
 * @subpackage home
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class homeActions extends sfActions {

    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeIndex(sfWebRequest $request) {

        $this->title = "Home";
        $this->breadcrumbs = array(array("Home","home/index"));

        /** Alerts **/
        $q = Doctrine_Query::create()
                ->from('Alerts s')
                ->innerJoin('s.Users u on u.id_users = s.id_user_creator ')
                ->where('s.id_users = ?' , array($this->getUser()->getAttribute('id_users')))
                ->addWhere('s.deleted = ?', array(0))
                ->orderBy('s.creation_date desc');
        
        $this->alerts = $q->fetchArray();
        
        
        /** User Logs **/
        $query = "select 
                    ul.title as title, u.name as user, ul.creation_date as creation, s.name store
                    from user_stores us
                    inner join user_logs ul on ul.id_store = us.id_store
                    inner join stores s on s.id_store = us.id_store
                    inner join users u on u.id_users = us.id_users
                    where us.id_users = ".$this->getUser()->getAttribute('id_users');

        $con = Doctrine_Manager::getInstance()->connection();
        $st = $con->execute($query);
        $this->logs = $st->fetchAll();
        
    }
    
    /**
     * Executes Logs Details action
     *
     * @param sfRequest $request A request object
     */
    public function executeLogsDetails(sfWebRequest $request) {
        
        $this->title = "Logs Detalles";
        $this->breadcrumbs = array(array("Home","home/index"),array("Logs Detalles","home/logsDetails"));
        
        /** User Logs **/
        $query = "select 
                    ul.title as title, u.name as user, ul.creation_date as creation, s.name store
                    from user_stores us
                    inner join user_logs ul on ul.id_store = us.id_store
                    inner join stores s on s.id_store = us.id_store
                    inner join users u on u.id_users = us.id_users
                    where us.id_users = ".$this->getUser()->getAttribute('id_users');

        $con = Doctrine_Manager::getInstance()->connection();
        $st = $con->execute($query);
        $this->logs = $st->fetchAll();
        
    }
    
    /**
     * Executes Logs Details action
     *
     * @param sfRequest $request A request object
     */
    public function executeAlertsDetails(sfWebRequest $request) {
        
        $this->title = "Alertas Detalles";
        $this->breadcrumbs = array(array("Home", "home/index"), array("Alertas Detalles", "home/alertsDetails"));
        
        /** Alerts **/
        $q = Doctrine_Query::create()
                ->from('Alerts s')
                ->where('s.id_users = ?' , array($this->getUser()->getAttribute('id_users')))
                ->addWhere('s.deleted = ?', array(0))
                ->orderBy('s.creation_date desc');
        
        $this->alerts = $q->fetchArray();
    }

}
